﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 打开
{
    class MessegeForm : Form
    {

        public enum ButtonKind
        {
            是否钮 = 1,
            确定钮 = 0
        }

        /*------------------------------------------------------------------*/

        public MessegeForm()
        {
            this.TopMost = true;
            this.Size = new Size(250, 165);
            //this.Icon = Resource1.logo1;
            this.MaximizeBox = this.MinimizeBox = false;
            this.FormBorderStyle = FormBorderStyle.FixedDialog;
            this.StartPosition = FormStartPosition.CenterParent;
            this.FormClosing += new FormClosingEventHandler(Closing_MessegeForm);
        }

        public void createForm(string msg, ButtonKind kind = ButtonKind.确定钮)
        {
            System.Media.SystemSounds.Beep.Play();

            Create_Button(kind);
            Create_Lable(msg);

            this.Text = "提示：";
            this.ShowDialog();
        }

        public void createForm(string msg, string caption, ButtonKind kind = ButtonKind.确定钮)
        {
            System.Media.SystemSounds.Beep.Play();

            Create_Button(kind);
            Create_Lable(msg);

            this.Text = caption;
            this.ShowDialog();
        }


        private void Create_Lable(string msg)
        {
            Label label = new Label();
            label.Font = new Font(label.Font.FontFamily, 9, label.Font.Style);
            label.TextAlign = ContentAlignment.MiddleCenter;
            label.Size = new Size(this.Width, 16);
            label.Location = new Point(-10, 32);
            label.Text = msg;
            label.Visible = true;
            this.Controls.Add(label);
        }

        private void Create_Button(ButtonKind kind)
        {
            Button sure = new Button();
            sure.Location = new Point(70, 78);
            sure.Size = new Size(90, 30);
            sure.TextAlign = ContentAlignment.MiddleCenter;
            sure.Font = new Font(sure.Font.FontFamily, 9);
            sure.Text = "确定";
            sure.Click += new EventHandler(Click_Sure);

            Button cancel = new Button();
            cancel.Location = new Point(120, 78);
            cancel.Size = new Size(90, 30);
            cancel.TextAlign = ContentAlignment.MiddleCenter;
            cancel.Font = new Font(sure.Font.FontFamily, 9);
            cancel.Text = "取消";
            cancel.Click += new EventHandler(Click_Cancel);

            if (kind == ButtonKind.确定钮)
            {
                cancel.Visible = false;
            }
            else if (kind == ButtonKind.是否钮)
            {
                sure.Left = 25;
            }

            this.Controls.Add(sure);
            this.Controls.Add(cancel);
        }

        private void Click_Sure(object sender, EventArgs e)
        {

            DialogResult = DialogResult.Yes;
            this.Close();
        }

        private void Click_Cancel(object sender, EventArgs e)
        {

            DialogResult = DialogResult.No;
            this.Close();
        }

        private void Closing_MessegeForm(object sender, EventArgs e)
        {
            //Console.WriteLine("ReturnValue: " + DialogResult);
            this.Controls.Clear();
            return;
        }
    }
}
